package com.dianrui.moonfire.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dianrui.moonfire.R;
import com.dianrui.moonfire.bean.MessageModel;


import java.util.List;

public class MessageAdapter extends BaseQuickAdapter<MessageModel, BaseViewHolder> {
    private Context context;

    public MessageAdapter(int layoutResId, @Nullable List<MessageModel> data, Context context) {
        super(layoutResId, data);
        this.context = context;
    }

    @SuppressLint("Range")
    @Override
    protected void convert(BaseViewHolder helper, MessageModel msgList) {
        helper.setText(R.id.title, msgList.title);
        helper.setText(R.id.time, msgList.create_time);
        helper.setText(R.id.content, msgList.contents);
        if (msgList.is_read == 1) {
            helper.setTextColor(R.id.title, context.getResources().getColor(R.color.nav_color_txt));
            helper.setTextColor(R.id.time, context.getResources().getColor(R.color.nav_color_txt));
            helper.setTextColor(R.id.content, context.getResources().getColor(R.color.nav_color_txt));
            helper.getView(R.id.msg_show_red_dot).setVisibility(View.GONE);//已读的不显示红点
            helper.getView(R.id.msg_img).setAlpha(0.7f);
        } else {
            helper.setTextColor(R.id.title, context.getResources().getColor(R.color.black));
            helper.setTextColor(R.id.time, context.getResources().getColor(R.color.black));
            helper.setTextColor(R.id.content, context.getResources().getColor(R.color.black));
            helper.getView(R.id.msg_show_red_dot).setVisibility(View.VISIBLE);
            helper.getView(R.id.msg_img).setAlpha(250f);
        }
        helper.addOnClickListener(R.id.click_message);
        helper.addOnLongClickListener(R.id.click_message);
        helper.addOnClickListener(R.id.delete);
    }
}
